﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LotteryVote.Entity;
using System.Data.SqlClient;

namespace LotteryVote.Data
{
    public class OrderAncestorCommInfoDataAccess : DataBase
    {
        public void Insert(OrderAncestorCommInfo commInfo)
        {
            string sql = string.Format(@"INSERT INTO {0} ({1},{2},{3},{4}) VALUES (@{1},@{2},@{3},@{4})",
                OrderAncestorCommInfo.TABLENAME, OrderAncestorCommInfo.ORDERID, OrderAncestorCommInfo.ROLEID,
                OrderAncestorCommInfo.COMMISSION, OrderAncestorCommInfo.COMMAMOUNT);
            base.ExecuteNonQuery(sql, new SqlParameter(OrderAncestorCommInfo.ORDERID, commInfo.OrderId),
                new SqlParameter(OrderAncestorCommInfo.ROLEID, commInfo.RoleId),
                new SqlParameter(OrderAncestorCommInfo.COMMISSION, commInfo.Commission),
                new SqlParameter(OrderAncestorCommInfo.COMMAMOUNT, commInfo.CommAmount));
        }

        public IList<OrderAncestorCommInfo> GetAncestorComms(BetOrder order)
        {
            string sql = string.Format(@"SELECT * FROM {0} WHERE {1}=@{1}", OrderAncestorCommInfo.TABLENAME, OrderAncestorCommInfo.ORDERID);
            return base.ExecuteList<OrderAncestorCommInfo>(sql, new SqlParameter(OrderAncestorCommInfo.ORDERID, order.OrderId));
        }
    }
}
